/*
Copyright 2020 yozora.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
	"github.com/fatih/color"
)

const (
	EggTile = '■'

	EggBlocker rune = iota
	EggSpeedBlocker
	EggScoreBlocker
)

type Egg struct {
	SpiritObject

	Marker rune
	Color  color.Attribute
	Pos    *Position
}

func NewRandomEgg(x float64, y float64) *Egg {

	var _type = EggBlocker
	if x < 0 && y < 0 {
		var i = random.Int31n(4)
		switch i {
		case 1:
			_type = EggSpeedBlocker
		case 2:
			_type = EggScoreBlocker

		}
	}

	if x < 0 {
		x = float64(random.Int31n(int32(gameWidth)))
	}
	if y < 0 {
		y = float64(random.Int31n(int32(gameHeight)))
	}

	return NewEgg(_type, x, y)

}

func NewEgg(_type rune, x float64, y float64) *Egg {
	_color := white
	switch _type {
	case EggBlocker:

	case EggScoreBlocker:
		_color = yellow
	case EggSpeedBlocker:
		_color = green

	}
	return &Egg{
		Marker: _type,
		Color:  _color,
		Pos: &Position{
			X: x,
			Y: y,
		},
	}
}

func (e Egg) render() string {
	switch e.Marker {
	case EggSpeedBlocker:
		return color.New(color.FgGreen).SprintFunc()(string(EggTile))
	case EggScoreBlocker:
		return color.New(color.FgYellow).SprintFunc()(string(EggTile))

	}

	return string(EggTile)
}

func (e Egg) score() int {
	switch e.Marker {
	case EggSpeedBlocker:
		return 1
	case EggScoreBlocker:
		return 2

	}

	return 1
}

func (e Egg) speed() (float64, float64) {
	switch e.Marker {
	case EggSpeedBlocker:
		return 2, 4

	}

	return 1, 0
}
